//
//  LatestCell.m
//  New
//
//  Created by 才诗琦 on 16/1/23.
//  Copyright © 2016年 www.lanou3g.com. All rights reserved.
//

#import "LatestCell.h"

@implementation LatestCell
- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        //背景图片
        self.bagImageView = [[UIImageView alloc] init];
        [_bagImageView setImage:[UIImage imageNamed:@"bg"]];
        [self.contentView addSubview:_bagImageView];
        [_bagImageView release];
        
        //提问者头像
        self.quesUser = [[UIImageView alloc] init];
        _quesUser.layer.cornerRadius = 15;
        _quesUser.clipsToBounds = YES;
        [self.bagImageView addSubview:_quesUser];
        [_quesUser release];
        //提问者名字
        self.quesUserNameLabel = [[UILabel alloc] init];
        [self.bagImageView addSubview:_quesUserNameLabel];
        [_quesUserNameLabel release];
        //提问内容
        
        self.quesLabel = [[UILabel alloc] init];
        _quesLabel.numberOfLines = 0;
        [self.bagImageView addSubview:_quesLabel];
        [_quesLabel release];
        
        //回复
        
        //头像
        self.ansUser = [[UIImageView alloc] init];
        _ansUser.layer.cornerRadius = 15;
        _ansUser.clipsToBounds = YES;
        
        [self.bagImageView addSubview:_ansUser];
        [_ansUser release];
        
        //名字
        self.ansUserNameLabel = [[UILabel alloc] init];
        [self.bagImageView addSubview:_ansUserNameLabel];
        [_ansUserNameLabel release];
        
        
        //内容
        self.ansLabel = [[UILabel alloc] init];
        _ansLabel.numberOfLines = 0;
        [self.bagImageView addSubview:_ansLabel];
        [_ansLabel release];
        
        
        //时间
        self.timeLabel = [[UILabel alloc] init];
        [self.bagImageView addSubview:_timeLabel];
        [_timeLabel release];
        

        
       //like
        
        self.like = [UIButton buttonWithType:UIButtonTypeCustom];
        [_like setImage:[UIImage imageNamed:@"zan1"] forState:UIControlStateNormal];
        [self.bagImageView addSubview:_like];
        
        
        //分享
        self.shareButton = [UIButton buttonWithType:UIButtonTypeCustom];
        [_shareButton setImage:[UIImage imageNamed:@"fenxiang1"] forState:UIControlStateNormal];
        [self.bagImageView addSubview:_shareButton];
        [self.shareButton release];
        
        //线
        self.line = [[UILabel alloc] init];
        _line.text = @"--------------------------------------";
        _line.textColor = [UIColor grayColor];
        [self.bagImageView addSubview:_line];
        [_line release];
    }
    
    return self;
    
}
- (void)layoutSubviews
{
    [super layoutSubviews];

    CGFloat h = [[self class] heightWithTextQ:_quesLabel.text];
    
    CGFloat h1 = [[self class] heightWithTextA:_ansLabel.text];
     self.bagImageView.frame = CGRectMake(5, 10, 365, h + 150 + h1);
    
    
    //提问者头像
    self.quesUser.frame = CGRectMake(10, 10, 30, 30);
    
    //提问者名字
    self.quesUserNameLabel .frame = CGRectMake(50, 10, self.bagImageView.frame.size.width - 70, 30);;
    
    //提问内容
    
    self.quesLabel .frame = CGRectMake(50, 40, self.bagImageView.frame.size.width - 70, h);;
       //回复
    
    //分割线
    self.line.frame = CGRectMake(50, h + 50, self.bagImageView.frame.size.width - 63, 20);
    
    //头像
    self.ansUser.frame = CGRectMake(10, h + 70, 30, 30);
    
    //名字
    self.ansUserNameLabel.frame = CGRectMake(50, h + 70, self.bagImageView.frame.size.width - 70, 30);
    
    
    //内容
    
   
    self.ansLabel.frame = CGRectMake(50, h + 100, self.bagImageView.frame.size.width - 70, h1);

    
    //时间
    self.timeLabel.frame = CGRectMake(50, h + 100 + h1,90, h1);
    
    
    
    //like
    
    self.like.frame = CGRectMake(280, h + 100 + h1, 30, 30);;
    
    
    
        //分享
    self.shareButton.frame = CGRectMake(330, h + 100 + h1, 30, 30);;
   
   

    
    
}
+(CGFloat)heightWithTextQ:(NSString *)str
{
    NSDictionary *dic = @{NSFontAttributeName:[UIFont systemFontOfSize:17]};
    CGSize size = CGSizeMake(315, 1000);
    CGRect rect = [str boundingRectWithSize:size options:NSStringDrawingUsesLineFragmentOrigin attributes:dic context:nil];
    
    return rect.size.height;
    
}
+(CGFloat)heightWithTextA:(NSString *)str
{
    NSDictionary *dic = @{NSFontAttributeName:[UIFont systemFontOfSize:17]};
    CGSize size = CGSizeMake(315, 1000);
    CGRect rect = [str boundingRectWithSize:size options:NSStringDrawingUsesLineFragmentOrigin attributes:dic context:nil];
    
    return rect.size.height;
    
}
- (void)awakeFromNib {
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
